﻿#pragma once

#include "../MirEnvir/Envir.h"
#include "../MessageQueue.h"
#include <string>
#include <vector>
#include <stdexcept>
#include <any>
#include <mutex>
#include "../../stringhelper.h"

using namespace Server::MirEnvir;

namespace Server::MirNetwork
{
    class MirStatusConnection
    {
    public:
        virtual ~MirStatusConnection()
        {
            delete _client;
        }

    protected:
        static Server::MirEnvir::Envir *getEnvir();
        static Server::MessageQueue *getMessageQueue();

    public:
        const std::string IPAddress;
    private:
        TcpClient *_client;

        long long NextSendTime = 0;

        bool _disconnecting = false;
    public:
        bool Connected = false;
        bool getDisconnecting() const;
        void setDisconnecting(bool value);
        const long long TimeConnected;
        long long TimeOutTime = 0;


        MirStatusConnection(TcpClient *client);

    private:
        void BeginSend(std::vector<unsigned char> &data);
        void SendData(IAsyncResult *result);

    public:
        void Process();
        void Disconnect();
        void SendDisconnect();
    };
}
